package com.example.ccj.b.c.ui.install;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.ccj.R;
import com.example.ccj.b.c.custom.MImageView;
import com.example.ccj.b.c.custom.MTextView;
import com.example.ccj.b.c.recycler.BaseRecycler;

import java.util.List;

public class AddOptionView extends LinearLayout {

    MTextView textView;
    MImageView addOption;
    BaseRecycler<String> recycler;
    
    public AddOptionView(Context context) {
        super(context);
        init();
    }

    public AddOptionView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init(){
        LayoutInflater.from(getContext()).inflate(R.layout.control_add_option_view,this);
        textView = findViewById(R.id.control_add_option_view_title);
        recycler = findViewById(R.id.control_add_option_view_rec);
        addOption = findViewById(R.id.control_add_option_view_add);

        //添加选项按钮弹出输入选项名称dialog
        addOption.setOnClickListener(v -> {
            AddOneOptionDialog addOneOptionDialog = new AddOneOptionDialog(v.getContext(), (value, val) -> addOneData(value));
            addOneOptionDialog.show();
        });
    }

    public void setData(List<String> vals){
        recycler.setAdapter(vals,new AddOptionAdapter(vals));
    }

    private void addOneData(String val){
        recycler.addDataOnTail(val);
    }

    public void setTitleName(String val){
        textView.setText(val);
    }



}
